home *** CD-ROM | disk | FTP | other *** search
- /* $Id: COMBhvr.cpp 1.9 1997/04/05 02:39:27 damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // Tree Behavior Example : ????? //
- //--------------------------------------------------------------------//
- // Implementation of the Behavior Interface //
- ////////////////////////////////////////////////////////////////////////
-
-
- #ifndef __COM_BHVR__
- #include "COMBhvr.h"
- #endif
-
- #ifndef __BHVR_DLL__
- #include "BhvrDLL.h"
- #endif
-
- #ifndef __I3DSHSCN__
- #include "I3DShScn.h"
- #endif
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- #undef INTERFACE
- #define INTERFACE Behavior
- // Constructor / Destructor of the C++ Object :
- Behavior::Behavior() {
- fCRef=0; // Reference Counter
- // Data initialisation :
- *fData.fNameObject1=0;
- *fData.fNameObject2=0;
- fData.fRelPos = 0.5; // 50% , at the middle of the two objects
- }
-
- Behavior::~Behavior() {
- global_count_Obj--;
- }
-
- // IUnknown Interface :
- HRESULT Behavior::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
- *ppvObj=NULL;
-
- // The Behavior knows the interfaces of the parent Objects
- if (IsEqualIID(riid, IID_IUnknown))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExTreeBehavior))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExDataExchanger))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExtension))
- *ppvObj=(LPVOID)this;
-
- // we must add reference if we return an interface
- if (*ppvObj!=NULL) {
- ((LPUNKNOWN)*ppvObj)->AddRef();
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
- ULONG Behavior::AddRef(THIS) {
- return fCRef++;
- }
-
- ULONG Behavior::Release(THIS) {
- ULONG UnreleaseObject=fCRef--;
-
- if (fCRef==0)
- delete this; // No reference left, so destroy the object
-
- return UnreleaseObject;
- // local variable used, because fCRef can be destroyed before.
- }
-
- // I3DExtension methods :
- I3DExtension* Behavior::Clone(THIS) {
- Behavior* theClone = new Behavior;
- if (theClone) {
- theClone->AddRef();
- theClone->fData=fData; // copy the BehaviorData
- }
- return theClone;
- }
-
- HRESULT Behavior::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
- InitCoFailure(shellUtilities);
- return NOERROR;
- }
-
- // I3DExDataExchanger methods :
- ExtensionDataMap* Behavior::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
- void* Behavior::GetExtensionDataBuffer(THIS) {
- return &fData; // used by the shell to set the new parameters
- }
-
- HRESULT Behavior::ExtensionDataChanged(THIS) {
- return NOERROR;
- }
-
- HRESULT Behavior::HandleEvent(THIS_ ULONG SourceID) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- short Behavior::GetResID(THIS) {
- return 142; // this is the view ID in the resource file.
- }
-
- // I3DExTreeBehavior methods :
- HRESULT Behavior::Apply(THIS_ I3DShTreeElement* tree) {
- TREETRANSFORM3D tr1;
- TREETRANSFORM3D tr2;
- TREETRANSFORM3D tr;
- I3DShTreeElement *tree1,*tree2;
- I3DShScene *scene;
- // Get the scene
- scene = tree->GetScene();
- if (!scene) return NOERROR; // abort any modifications if you can not get the scene
-
- // Search tree element 1 by name
- tree1 = scene->GetTreeElementByName(fData.fNameObject1);
- if (!tree1) return NOERROR; // abort because object 1 not found
- tree1->GetGlobalTransform8(&tr1);
-
- // Search tree element 2 by name
- tree2 = scene->GetTreeElementByName(fData.fNameObject2);
- if (!tree2) return NOERROR; // abort because object 2 not found
- tree2->GetGlobalTransform8(&tr2);
-
- // Set the new position of tree
- tree->GetGlobalTransform8(&tr);
- tr.fT[0] = tr1.fT[0] + (tr2.fT[0] - tr1.fT[0]) * fData.fRelPos ;
- tr.fT[1] = tr1.fT[1] + (tr2.fT[1] - tr1.fT[1]) * fData.fRelPos ;
- tr.fT[2] = tr1.fT[2] + (tr2.fT[2] - tr1.fT[2]) * fData.fRelPos ;
- tree->SetGlobalTransform8(&tr);
- return NOERROR;
- }
-
- HRESULT Behavior::SetGlobalTransform (THIS_ I3DShTreeElement *atree,const MATRIX3D *RR,const VECTOR3D *TT,short mode) {
- return ResultFromScode(E_NOTIMPL);
- }
-